// pages/store/store.js
const util = require("../../../utils/util.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hiddenLoading: true    
  },
  goDetail: function (e) {    
    var sid = e.currentTarget.dataset.sid;    
    wx.navigateTo({
      url: '../../home/detail/detail?sid='+sid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.ShowLoading();
    var userid = wx.getStorageSync('UserID') || []    
    if(userid!=""){
      this.GetSupplierListByUID(userid);
    }else{
      wx.navigateBack({ //如果没有获取到userid，就返回我的
        delta: 1
      })
    }
    
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      hiddenLoading: false
    });
    var that = this;
    setTimeout(function () {
      wx.stopPullDownRefresh();
      that.setData({
        hiddenLoading: true
      });
      console.log(that)
    }, 1500);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  ShowLoading:function(){ //加载Loading
    this.setData({
      hiddenLoading: false
    });
    var that = this;
    setTimeout(function () {
      that.setData({
        hiddenLoading: true
      });
    }, 1500);
  },
  GetSupplierListByUID:function(uid){  //根据用户ID 查询商户
    var that = this;
    var address = wx.getStorageSync('AddressInfo') || []
    var data = {
      userid: uid,
      lat:address.location.lat,
      lng:address.location.lng
    };
    data.act = "Find_SupplierAllByUIDAndStore";
    util.Ajax(data, function (json) {
      if (json.count > 0) {
        that.setData({SupplierList:json.data});
      }else{
        console.log("暂无收藏");
      }

    });
  }

})